import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import "./styles/demo.scss"
import "../../src/styles/themes.scss"

export default async ({ Vue, router }) => {
  if (typeof process === 'undefined') {
    Vue.use(ElementUI)
    
    // 自动注册自定义组件
    const requireComponent = require.context( '../../src/components/', true, /index\.vue$/)
    requireComponent.keys().forEach(fileName => {
      var componentName = fileName.replace(/(\.\/common\/|\.\/business\/|\/index\.vue)/g, '');
      if(componentName.indexOf('\/') == -1) {
        const componentConfig = requireComponent(fileName)
        Vue.component(componentName, componentConfig.default || componentConfig)
      }
    })

    // 监听页面加载完成
    router.afterEach(() => {
      setTimeout(() => {
        let aDom = document.querySelectorAll('*');
        for(let i = 0; i < aDom.length; i++) {
          let oDom = aDom[i];
          if(!oDom.closest('.demo-block.demo-en-US.demo-')) {
            oDom.classList.add('_vuepress_markdown_');
          }
        }
      }, 100);
    })
  }
}